var selectR;
function selectTypeRow(selObj,typeKind){
    selectR=selObj;
    var typeId=selObj.cells(1).innerText;
    parent.valfm.location.href=top.tophead.ctxpath+"/admin/DictCtrl!typeValues.do?typeId="+typeId+"&typeKind="+typeKind+"&valMgrflag="+$("#valMgrflag").val();
    $("#bTypeUpd").removeAttr("disabled");
    $("#bTypeDel").attr("disabled",false);
}
function refrenshTypeVals(){
    var typeId=selectR.cells(1).innerText;
    var typeKind=selectR.cells(0).title;
    parent.valfm.location.href=top.tophead.ctxpath+"/admin/DictCtrl!typeValues.do?typeId="+typeId+"&typeKind="+typeKind+"&valMgrflag="+$("#valMgrflag").val();
}
function typeAdd(){
    $("#oprflag").val("0")
    var url=top.tophead.ctxpath+"/admin/dict/DictTypeMgr.jsp";
    window.showModalDialog(url,this,"dialogHeight:240px;dialogWidth:320px");
    this.location.reload();
//    window.showModelessDialog(url,this,"");
}
function typeUpd(){
    $("#oprflag").val("1")
    var url=top.tophead.ctxpath+"/admin/dict/DictTypeMgr.jsp";
    window.showModalDialog(url,this,"dialogHeight:240px;dialogWidth:320px");
    this.location.reload();
}
function typeDel(){
    if(!confirm("确定要删除吗？\n删除类型会将对应的类型值一起删除")){
        return;
    }
    if(selectR){
        var typeId=selectR.cells(1).innerText;
        if(typeId && typeId!=""){
            var paras={
                "typeId":typeId
            }
            execAjax(top.tophead.ctxpath+"/admin/DictCtrl!delType.do",paras,function(result){
                alert(result.message);
                if(result.flag){
                    this.location.reload();
                }
            });
        }else{
            alert("请选择要删除的记录！");
        }
    }
}
function initTypeMgr(){
    $("#flag").val(dialogArguments.document.getElementById("oprflag").value);
    if($("#flag").val()=="0"){
        $(document).attr("title","类型添加");
        tabTitle.innerText="类型添加";
    }else{
        $(document).attr("title","类型修改");
        tabTitle.innerText="类型修改";
        var updType=dialogArguments.selectR;
        $("#oldTypeId").val(updType.cells(1).innerText);
        $("#typeId").val(updType.cells(1).innerText);
        $("#typeKind").val(updType.cells(0).innerText);
        $("#typeName").val(updType.cells(2).innerText);
        $("#memo").val(updType.cells(2).title);
        $("#typeKind").attr("disabled",true);
    }
}
function typeSubmit(){
    if($("#typeId").val()==""){
        alert("类型ID不能为空！");
        return;
    }
    if($("#typeName").val()==""){
        alert("类型名称不能为空！");
        return;
    }
    var paras=new Map();
    paras.put("typeId",$("#typeId").val());
    paras.put("typeKind",$("#typeKind").val());
    paras.put("typeName",$("#typeName").val());
    paras.put("memo",$("#memo").val());
    if($("#flag").val()=="0"){ //增加类型
        execAjax($("#ctxpath").val()+"/admin/DictCtrl!addType.do",paras.toObj(),function(result){
            alert(result.message);
            if(result.flag){
                window.close();
            }
        })
    }else{ //修改类型
        paras.put("oldTypeId",$("#oldTypeId").val())
        execAjax($("#ctxpath").val()+"/admin/DictCtrl!updateType.do",paras.toObj(),function(result){
            alert(result.message);
            if(result.flag){
                window.close();
            }
        })
    }
}